pub mod core;
pub mod config;
pub mod utils;
use once_cell::sync::OnceCell;
use crate::config::{config::Config, load::load_config};

pub static CONFIG: OnceCell<Config> = OnceCell::new();

pub fn get_config() -> &'static Config {
    CONFIG.get_or_init(|| load_config().unwrap())
}

use std::collections::HashMap;
use std::sync::Mutex;
use std::time::{SystemTime};
use uuid::Uuid;
struct HostRegistry {
    hosts: Mutex<HashMap<Uuid, (String, SystemTime)>>, // ID -> (主机名, 最后更新时间)
}

impl HostRegistry {
    pub fn update_host(&self, id: Uuid, name: String) {
        let mut hosts = self.hosts.lock().unwrap();
        hosts.insert(id, (name, SystemTime::now()));
    }

    pub fn remove_expired(&self, timeout_secs: u64) {
        let mut hosts = self.hosts.lock().unwrap();
        hosts.retain(|_, (_, time)| time.elapsed().unwrap().as_secs() < timeout_secs);
    }
}